#include "talisman.h"
#include "Map\Map.h"
#include "Map\PositionKeeper.h"
#include <QtGui>

/* Initialization */
Talisman::Talisman(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
	, mapFileName("")
	, characterFileName("")
	, mAdventureCardArea(0)
	, alignmentGroup(0)
	, mPositionKeeper(0)
	, mPlayer(0)
	, map(0)
	, leftPanel(0)
	, mUseAdventureCardButton(0)
{
	try
	{
		setup();
		QFile File("style.css");

		File.open(QFile::ReadOnly);
		QString StyleSheet = QLatin1String(File.readAll());
		if (StyleSheet.length() == 0)
			throw "Stylesheet wasn't found.";

		qApp->setStyleSheet(StyleSheet);
	}
	catch (char *e)
	{
		QMessageBox msgBox;
		QString msg (e);
		msgBox.setText(msg);
		msgBox.setIcon(QMessageBox::Information);
		msgBox.exec();
	}
}

/* destructor */
Talisman::~Talisman()
{
	// Delete all controls
	if (0 != alignmentGroup)
		delete alignmentGroup;

	if (0 != layout)
		delete layout;

	if (0 != mPositionKeeper)
		delete mPositionKeeper;

	if (0 != map)
		delete map;

	/* -- deleted somewhere else
	if (0 != mPlayer)
		delete mPlayer;
		*/

	if( 0 != mLoadMapButton)
		delete mLoadMapButton;
	if( 0 != mRollDie)
		delete mRollDie;
	if( 0 != mBackButton)
		delete mBackButton;
	if( 0 != mForwardButton)
		delete mForwardButton;
	if( 0 != mBridgeButton)
		delete mBridgeButton;
	if( 0 != mPortalButton)
		delete mPortalButton;
	if( 0 != mLoadCharacterButton)
		delete mLoadCharacterButton;
	if( 0 != mEditMapButton)
		delete mEditMapButton;
	if( 0 != mEditCharacterButton)
		delete mEditCharacterButton;
	if (0 != mUseAdventureCardButton)
		delete mUseAdventureCardButton;
}
